<?php

namespace app\validate\home;

use app\common\validate\BaseValidate;

/**
 * Class Validate
 * https://www.kancloud.cn/manual/thinkphp6_0/1037624
 * @package app\daily\validate
 */
class Duty extends BaseValidate
{
    //定义验证规则
    protected $rule = [
        'store_id|门店id' => 'require|number',
        'duty_date|日期' => 'require|checkDate',
        'start_time|开始时间' => 'require',
        'end_time|结束时间' => 'require',
        'position|职位' => 'require',
    ];
    //定义验证场景要与方法名相同走自动验证
    protected $scene = [
        'create' => ['store_id', 'duty_date', 'start_time'],
    ];

    // 自定义验证规则
    protected function checkDate($value, $rule, $data = [])
    {
        $nowDate = date('Y-m-d');
        if ($value < $nowDate) {
            return "日期不正确";
        } else {
            return true;
        }
    }
}
